package com.qf.fmall2203.orders.controller;

import com.qf.fmall2203.orders.entity.Orders;
import com.qf.fmall2203.orders.service.IOrdersService;
import com.qf.fmall2203.vo.ResultVo;
import com.qf.fmall2203.weixin.WxpayUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 订单  前端控制器
 * </p>
 *
 * @author ljc
 * @since 2023-02-16
 */
@RestController
@RequestMapping("/order")
@CrossOrigin
@Slf4j
public class OrdersController {

    @Autowired
    IOrdersService ordersService;
    @PostMapping("/add")
    public ResultVo orderAdd(Integer[] cids,@RequestBody Orders orders) throws Exception {
    log.debug("cids:{},orders:{}",cids,orders);

    Map<String,Object> data = ordersService.add(cids,orders);

    return ResultVo.ok(data);
    }
    @GetMapping("/status/{orderId}")
    public ResultVo orderPay(@PathVariable("orderId") String orderId) throws Exception {
        String payUrl = WxpayUtils.queryOrder(orderId);
        if (payUrl.equals("SUCCESS")){

            return ResultVo.ok(2);
        }

        return ResultVo.ok("支付失败");
    }


}
